<template>
    <el-container>
        <!-- 侧边栏区域 -->
        <el-aside width="auto" style="background-color: rgb(15, 22, 66, 1)">
            <el-menu :default-openeds="['1', '2', '3', '4', '5', '6', '7', '8']" background-color="rgb(15, 22, 66, 1)"
                text-color="rgba(157, 163, 204, 1)">
                <h1>百思商城商家后台</h1>
                <div class="switchCompany">
                    <div class="image">
                        <img src="../assets/store.png">
                    </div>
                    <div class="text">
                        <p class="companyTitle">{{ UserMessage.tenantName }}</p>
                        <p class="storeId">店铺ID：{{ UserMessage.tenantIdNow }}</p>
                    </div>
                    <div class="icon">
                        <i class="el-icon-d-caret"></i>
                    </div>
                    <div class="companyList" style="overflow-y:scroll;overflow-x:hidden;">
                        <div class="company" v-for=" item  in  UserMessage.userTenants " :key="item.id" @click="change(item.id)">
                            <div class="image">
                                <img src="../assets/store.png" v-if="item.avatar == null">
                                 <img :src="item.avatar || defaultImage" @error="e => { e.target.src = defaultImage }" v-else />
                            </div>
                            <div class="text">
                                <p class="companyTitle">{{ item.tenantName }}</p>
                                <p class="storeId">店铺ID：{{ item.id }}</p>
                            </div>
                            <div class="icon">
                                <i class="el-icon-d-caret"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <el-submenu index="1">
                    <template slot="title">
                        <i class="commodity-icon"></i>商品管理</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('CommodityList')">
                                <span v-if="selectIndex == 'CommodityList'">商品列表</span>
                                <span v-else style="color: white;">商品列表</span>
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="2">
                    <template slot="title"><i class="inventory-icon"></i>库存管理</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('CommodityStockroom')">
                                <span v-if="selectIndex == 'CommodityStockroom'">商品入库</span>
                                <span v-else style="color: white;">商品入库</span>
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('StockCount')">
                                <span v-if="selectIndex == 'StockCount'">库存盘点</span>
                                <span v-else style="color: white;">库存盘点</span>
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="3">
                    <template slot="title"><i class="marketing-icon"></i>营销管理</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('CommodityPricing')">
                                <span v-if="selectIndex == 'CommodityPricing'">商品定价</span>
                                <span v-else style="color: white;">商品定价</span>
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('FlashActivity')">
                                <span v-if="selectIndex == 'FlashActivity'">秒杀活动</span>
                                <span v-else style="color: white;">秒杀活动</span>
                            </div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('RecommendedGoods')">
                                <span v-if="selectIndex == 'RecommendedGoods'">专题推荐</span>
                                <span v-else style="color: white;">专题推荐</span>
                            </div>
                        </el-col>
                        <el-col :span="6" style="padding-left:3px">
                            <div @click="handleClick('')">
                                优惠卷
                            </div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12" style="padding-left:13px">
                            <div @click="handleClick('ProductListRemove')">
                                <span v-if="selectIndex == 'ProductListRemove'">商品上下架</span>
                                <span v-else style="color: white;">商品上下架</span>
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('')">
                                广告投放
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="4">
                    <template slot="title"><i class="order-icon"></i>订单管理</template>
                    <el-row>
                        <el-col :span="10">
                            <div @click="handleClick('ToBeShippedOrder')">
                                <span v-if="selectIndex == 'ToBeShippedOrder'">待发货</span>
                                <span v-else style="color: white;">待发货</span>
                            </div>
                        </el-col>
                        <el-col :span="10">
                            <div @click="handleClick('ShippedOrder')">
                                <span v-if="selectIndex == 'ShippedOrder'">已发货</span>
                                <span v-else style="color: white;">已发货</span>
                            </div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="10">
                            <div @click="handleClick('completedOrder')">
                                <span v-if="selectIndex == 'completedOrder'">已完成</span>
                                <span v-else style="color: white;">已完成</span>
                            </div>
                        </el-col>
                        <el-col :span="10">
                            <div @click="handleClick('ReturnOExchangeOrder')">
                                <span v-if="selectIndex == 'ReturnOExchangeOrder'">退换货</span>
                                <span v-else style="color: white;">退换货</span>
                            </div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="10" style="padding-left:13px">
                            <div @click="handleClick('AllOrders')">
                                <span v-if="selectIndex == 'AllOrders'">所有订单</span>
                                <span v-else style="color: white;">所有订单</span>
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="5">
                    <template slot="title"><i class="consult-icon"></i>咨询及评价</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('ConusltManager')">
                                <span v-if="selectIndex == 'ConusltManager'">商品咨询</span>
                                <span v-else style="color: white;">商品咨询</span>
                                <div class="chatBubble">
                                    {{ rowCount }}
                                </div>
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('')">
                                订单评价
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="6">
                    <template slot="title"><i class="store-icon"></i>店铺管理</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('')">
                                店铺装修
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('')">
                                店铺认证
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="7">
                    <template slot="title"><i class="account-icon"></i>账户管理</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('')">
                                账户信息
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('')">
                                收入流水
                            </div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('')">
                                支出流水
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
                <el-submenu index="8">
                    <template slot="title"><i class="security-icon"></i>安全权限</template>
                    <el-row>
                        <el-col :span="12">
                            <div @click="handleClick('')">
                                用户管理
                            </div>
                        </el-col>
                        <el-col :span="8">
                            <div @click="handleClick('')">
                                角色权限
                            </div>
                        </el-col>
                    </el-row>
                </el-submenu>
            </el-menu>
        </el-aside>
        <!-- 主体区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header style="text-align: right; font-size: 12px">
                <el-row type="flex" justify="end">
                    <el-col :span="1">
                        <div class="hBox">
                            <i class="hIcon"></i>
                            <p class="hText">规则</p>
                        </div>
                    </el-col>
                    <el-col :span="1">
                        <div class="hBox">
                            <i class="hIcon"></i>
                            <p class="hText">教程</p>
                        </div>
                    </el-col>
                    <el-col :span="1">
                        <div class="hBox">
                            <i class="hIcon"><i class="dotIcon"></i></i>
                            <p class="hText">消息</p>
                        </div>
                    </el-col>
                    <el-col :span="1">
                        <div class="hBox">
                            <i class="hIcon"></i>
                            <p class="hText">客服</p>
                        </div>
                    </el-col>
                    <el-col :span="1">
                        <div class="hBox">
                            <i class="hIcon"></i>
                            <p class="hText">反馈</p>
                        </div>
                    </el-col>
                    <el-col :span="2">
                        <div class="userInfo">
                            <p class="userIdentity"><i class="el-icon-caret-bottom"></i></p>
                            <div class="userMes">
                                <img src="https://img.js.design/assets/smartFill/img341164da748e08.jpg" />
                                <div class="user">
                                    <p>{{ UserMessage.nickName == null ? UserMessage.realname : UserMessage.nickName }}</p>
                                </div>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </el-header>
            <!-- 列表区域 -->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>


<script>
import '@/styles/tableList.css';
import '@/styles/popDialog.css';
import { queryUserMessage,changecompanies } from '@/api/api.js'
import { mapGetters } from 'vuex';
import defaultImage from '@/assets/store.png'

export default {
    data() {
        return {
            UserMessage:{},
            defaultImage,
            selectIndex: new URL(window.location.href).hash.split('/')[2] === '' ? 'CommodityList' : new URL(window.location.href).hash.split('/')[2],
        }
    },
    async created() {
        const tenantId = sessionStorage.getItem('tenantId')
        const res = await queryUserMessage(tenantId)
        this.UserMessage = res.data.result
        sessionStorage.setItem('shopid',res.data.result.tenantIdNow)
        this.$store.state.shopid = res.data.result.id
    },
    methods: {
        handleClick(path) {
            this.$router.push({
                path
            })
            this.selectIndex = path
        },
        async change(targetid){
            console.log("切换企业")
            const res = await changecompanies(targetid)
            const resultshop = res.data.result.tenants.filter(el=>{
                return el.id === targetid
            })
            sessionStorage.setItem('tenantId',resultshop[0].id)
            sessionStorage.setItem('shopid',resultshop[0].id)
            queryUserMessage(resultshop[0].id)
        }
    },
    computed: {
        ...mapGetters(['rowCount'])
    }
};
</script>

<style>
* {
    margin: 0;
    padding: 0;
}

.el-container {
    width: 100vw;
    height: 100vh;
    background-color: rgba(247, 249, 250, 1);
}

/* 头部区域 */

.el-header {
    color: #333;
    line-height: 60px;
}

.el-header .el-row {
    margin-right: 45px;
}

.el-header .el-row .el-col {
    width: 51px;
}

.el-header .el-row .el-col:last-child {
    width: 120px;
}

.el-header .el-row .el-col:nth-child(-n+5) {
    margin-top: 15px;
}

.el-header .el-row .el-col .hBox {
    display: flex;
    flex-direction: column;
    justify-items: center;
    align-items: center;
    box-sizing: border-box;
    color: rgba(94, 108, 132, 1);
    cursor: pointer;
}

.el-header .el-row .el-col .hBox .hIcon {
    display: inline-block;
    width: 16px;
    height: 16px;
    background-size: 16px 16px;
    background-image: url('../assets/rule.png');
}

.el-header .el-row .el-col:nth-child(2) .hBox .hIcon {
    background-image: url('../assets/tutorial.png');
}

.el-header .el-row .el-col:nth-child(3) .hBox .hIcon {
    position: relative;
    background-image: url('../assets/message.png');
}

.el-header .el-row .el-col:nth-child(3) .hBox .hIcon .dotIcon {
    position: absolute;
    top: -2px;
    right: -4px;
    width: 8px;
    height: 8px;
    background-size: 8px 8px;
    background-image: url('../assets/dot.png');
}

.el-header .el-row .el-col:nth-child(4) .hBox .hIcon {
    background-image: url('../assets/customerService.png');
}

.el-header .el-row .el-col:last-child .hBox .hIcon {
    background-image: url('../assets/feedback.png');
}

.el-header .el-row .el-col .hBox .hIcon:hover,
.userInfo:hover {
    cursor: pointer;
}

.el-header .el-row .el-col .hBox .hText {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0px;
    line-height: 16.8px;
    margin-top: 8px;
}

.el-header .el-row .el-col .userInfo {
    display: flex;
    flex-direction: column;
    width: 120px;
    height: 60px;
    margin-left: 15px;
}

.el-header .el-row .el-col .userInfo p {
    font-size: 12px;
    font-weight: 400;
    line-height: 17.38px;
    opacity: 1;
    color: rgba(255, 255, 255, 1);
}

.el-header .el-row .el-col .userInfo .userMes {
    display: flex;
}

.el-header .el-row .el-col .userInfo .userMes img {
    width: 36px;
    height: 38px;
    border-radius: 18px;
}

.el-header .el-row .el-col .userInfo .userMes .user {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-left: 8px;
    margin-top: 12px;
}

.el-header .el-row .el-col .userInfo .userMes .user p{
    font-size: large;
    color: black !important;
}

.el-header .el-row .el-col .userInfo .userMes .user p:first-child {
    color: rgba(52, 69, 99, 1);
}

.el-header .el-row .el-col .userInfo .userMes .user p:last-child {
    color: rgba(191, 202, 222, 1);
}

/* 侧边栏区域 */

.el-aside .el-menu {
    width: 230px;
    border-right: none;
}

.el-aside .el-menu .el-submenu .el-submenu__title .el-icon-arrow-down::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background-size: 8px 8px;
    background-image: url('../assets/arrowDown.png');
    margin-top: 5px;
}

.el-aside .el-menu .el-submenu .el-submenu__title:hover .el-icon-arrow-down::before {
    background-image: url('../assets/arrowHover.png');
}


.el-aside .el-menu .el-submenu .el-submenu__title i[class$="icon"] {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin: 0 10px 5px 0;
    background-size: 16px 16px;
}

.el-aside .el-menu .el-submenu:first-of-type .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/commodityManage.png');
}

.el-aside .el-menu .el-submenu:nth-of-type(2) .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/inventoryManage.png');
}

.el-aside .el-menu .el-submenu:nth-of-type(3) .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/marketingManage.png');
}

.el-aside .el-menu .el-submenu:nth-of-type(4) .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/orderManage.png');
}

.el-aside .el-menu .el-submenu:nth-of-type(5) .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/consultManage.png');
}

.el-aside .el-menu .el-submenu:nth-of-type(5) .el-row .el-col:first-child div {
    position: relative;
}

.el-aside .el-menu .el-submenu:nth-of-type(5) .el-row .el-col:first-child .chatBubble {
    position: absolute;
    top: 0px;
    right: 4px;
    width: 18px;
    height: 18px;
    line-height: 18px;
    border-radius: 9px;
    text-align: center;
    font-size: 10px;
    font-weight: 500;
    background-color: rgba(126, 114, 242, 1);
}


.el-aside .el-menu .el-submenu:nth-of-type(6) .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/storeManage.png');
}

.el-aside .el-menu .el-submenu:nth-of-type(7) .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/accountManage.png');
}

.el-aside .el-menu .el-submenu:last-of-type .el-submenu__title i[class$="icon"] {
    background-image: url('../assets/securityManage.png');
}

.el-aside .el-menu h1 {
    width: 160px;
    height: 24px;
    opacity: 1;
    font-family: "阿里妈妈数黑体 Bold";
    font-size: 20px;
    font-weight: 400;
    line-height: 24px;
    color: rgba(126, 114, 242, 1);
    text-align: center;
    vertical-align: top;
    margin: 25px;
}

.el-aside .el-menu .switchCompany,
.company {
    display: flex;
    align-items: center;
}

.el-aside .el-menu .switchCompany {
    position: relative;
    width: 210px;
    height: 56px;
    opacity: 1;
    border-radius: 5px;
    background: rgba(4, 8, 33, 1);
    margin: 0 9px;
}

.el-aside .el-menu .switchCompany .image {
    width: 40px;
    height: 40px;
    margin-left: 10px;
}

.el-aside .el-menu .switchCompany .image img {
    width: 100%;
}

.el-aside .el-menu .switchCompany .text {
    margin-left: -4px;
    font-size: 14px;
    font-weight: 500;
    line-height: 19.6px;
    color: rgba(255, 255, 255, 1);
}

.el-aside .el-menu .switchCompany .text p:first-child {
    margin-left: 13px;
}

.el-aside .el-menu .switchCompany .text p:last-child {
    font-size: 12px;
    font-weight: 500;
    line-height: 16.8px;
    opacity: 0.4;
    color: rgba(255, 255, 255, 1);
    margin: 2px 0 0 14px;
}

.el-aside .el-menu .switchCompany .icon {
    width: 14px;
    height: 14px;
    line-height: 14px;
    opacity: 0.33;
    color: rgba(255, 255, 255, 1);
    margin-left: 13px;
}

.el-aside .el-menu .switchCompany:hover .companyList {
    cursor: pointer;
    display: block;
    z-index: 999;
}

.el-aside .el-menu .switchCompany .companyList {
    display: none;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 210px;
    height: 199px;
    opacity: 1;
    border-radius: 5px;
    background: rgba(255, 255, 255, 1);
}

.el-aside .el-menu .switchCompany .companyList .company {
    height: 65px;
}

.el-aside .el-menu .switchCompany .companyList .company:hover {
    background-color: rgba(247, 249, 252, 1);
    border-radius: 5px;
}

.el-aside .el-menu .switchCompany .companyList .company:last-child {
    height: 69px;
}

.el-aside .el-menu .switchCompany .companyList .company .text p:first-child {
    color: rgba(52, 69, 99, 1);
}

.el-aside .el-menu .switchCompany .companyList .company .text p:last-child {
    opacity: 1;
    color: rgba(167, 180, 204, 1);
}

.el-aside .el-menu .switchCompany .companyList .company .icon {
    display: none;
    opacity: 1;
    color: rgba(94, 108, 132, 1);
}

.el-aside .el-menu .switchCompany .companyList .company:hover .icon {
    display: block;
}

.el-aside .el-menu .el-submenu .el-submenu__title {
    font-size: 12px;
    font-weight: 500;
}

.el-aside .el-menu .el-submenu .el-submenu__title:hover {
    background-color: rgb(15, 22, 66, 1) !important;
}

.el-aside .el-menu .el-submenu .el-submenu__title i[class^=icon] {
    display: inline-block;
    width: 16px;
    height: 16px;
    background-size: 16px 16px;
    margin: 0 10px 5px 0;
    background-color: pink;
}

.el-aside .el-menu .el-submenu .el-row {
    margin: 0 0 20px 20px;
    font-size: 13px;
    font-weight: 500;
    line-height: 18.2px;
    text-align: center;
    color: rgba(255, 255, 255, 1);
}

.el-aside .el-menu .el-submenu .el-row .el-col:nth-child(2) {
    margin-left: 6px;
}

.el-aside .el-menu .el-submenu .el-row .el-col div:hover {
    cursor: pointer;
    color: rgba(172, 163, 255, 1);
}
.el-aside .el-menu .el-submenu .el-row .el-col div span {
    cursor: pointer;
    color: rgba(172, 163, 255, 1);
}
.storeId{
  white-space:nowrap;
  /*强制单行显示*/
   text-overflow:ellipsis;
   /*超出部分省略号表示 */
  overflow:hidden;
  /*超出部分隐藏*/
  width: 100px;
  /*设置显示的最大宽度*/
}
</style>
